[id].vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <template>
  2. <!-- 页面头部 -->
  3. <HomePageHead></HomePageHead>
  4. <!-- 导航栏 -->
  5. <HomePageNavigation></HomePageNavigation>
  6. <!-- 列表页广告一 -->
  7. <HomeTopTen :imgurl="adImg1" v-if="adImg1"></HomeTopTen>
  8. <!-- 资讯列表 -->
  9. <div class="newsDetail">
  10. <div class="inner">
  11. <div class="innerLeft">
  12. <!-- 面包屑导航 -->
  13. <div class="breadcrumb">
  14. <div class="inner">
  15. <span class="location">当前位置:</span>
  16. <el-breadcrumb :separator-icon="ArrowRight">
  17. <el-breadcrumb-item>
  18. <NuxtLink to="/">首页</NuxtLink>
  19. </el-breadcrumb-item>
  20. <el-breadcrumb-item v-if="parent_name != ''">
  21. <NuxtLink :to="`/${parent_pinyin}/index.html`"> {{ parent_name }}</NuxtLink>
  22. </el-breadcrumb-item>
  23. <<<<<<< HEAD
  24. =======
  25. <el-breadcrumb-item v-if="parent_children_count == 0||parent_children_count==''||parent_children_count==null">
  26. <NuxtLink :to="`/${parent_pinyin}/list-1.html`"> {{ parent_name }}</NuxtLink>
  27. </el-breadcrumb-item>
  28. >>>>>>> 6f7f78215e97bb9cd6b05dcdc651d07789b7b45f
  29. <el-breadcrumb-item>
  30. <NuxtLink :to="`list-1.html`"> {{ routLevelTitle }}</NuxtLink>
  31. </el-breadcrumb-item>
  32. <el-breadcrumb-item>{{ routeNewsTtitle }}</el-breadcrumb-item>
  33. </el-breadcrumb>
  34. </div>
  35. </div>
  36. <div class="LeftTop">
  37. <h1>{{ newsDetail.title }}</h1>
  38. <p>
  39. 来源: <span>{{ newsDetail.copyfrom }}</span>
  40. 作者: <span>{{ newsDetail.author }}</span>
  41. 发布时间: <span>{{ time }}</span>
  42. </p>
  43. </div>
  44. <div class="leftBottom" v-html="newsDetail.content" v-if="newsDetail.content" @click="openPreview">
  45. </div>
  46. <div v-if="previewVisible" class="preview-modal" @click="closePreview">
  47. <img :src="selectedImage" alt="Preview">
  48. </div>
  49. <!-- 免责声明: -->
  50. <div class="disclaimer" v-if="newsDetail.copyfrom == '本网'">
  51. <p>原文链接:{{ newsDetail.fromurl }}</p>
  52. <p>[免责声明]本文来源于网络转载,仅供学习交流使用,不构成商业目的。 版权归原作者所有,如涉及作品内容,版权和其他问题,请在30日与本网联系,我们将第一时间处理。</p>
  53. </div>
  54. <div v-if="articleChoice">
  55. <HomeSurveyvote></HomeSurveyvote>
  56. </div>
  57. </div>
  58. <div class="innerRight">
  59. <!-- 热点资讯1 -->
  60. <div class="hotList1">
  61. <DetailHotNews></DetailHotNews>
  62. </div>
  63. <!-- 热点资讯2 -->
  64. <div class="hotList2">
  65. <DetailHotNews2></DetailHotNews2>
  66. </div>
  67. </div>
  68. </div>
  69. </div>
  70. <!-- 列表页广告一 -->
  71. <HomeTopTen :imgurl="adImg1" v-if="adImg2"></HomeTopTen>
  72. <!-- 页面底部 -->
  73. <HomeFoot1></HomeFoot1>
  74. </template>
  75. <script setup>
  76. //1.页面依赖 start ---------------------------------------->
  77. import { onMounted } from 'vue'
  78. import { ElBreadcrumb, ElBreadcrumbItem, ElRadio, ElRadioGroup, ElCheckbox, ElCheckboxGroup, ElMessage, ElInput } from 'element-plus'
  79. import { ArrowRight } from '@element-plus/icons-vue'
  80. //1.页面依赖 end ---------------------------------------->
  81. //2.页面路径 start ---------------------------------------->
  82. const route = useRoute();
  83. const articleId = parseInt(route.params.id);
  84. const targetSegment = getRoutePath(1);
  85. let routeId;
  86. //通过导航路径反向查询导航id
  87. const getRouteId = await requestDataPromise('/web/getWebsiteRoute', {
  88. method: 'GET',
  89. query: {
  90. 'pinyin': targetSegment,
  91. },
  92. });
  93. if (getRouteId.code == 200) {
  94. routeId = getRouteId.data.category_id
  95. } else {
  96. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  97. console.log("错误位置:通过url路径查询导航池id")
  98. console.log("后端错误反馈:", getRouteId.message)
  99. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  100. }
  101. //2.页面路径 end ---------------------------------------->
  102. //3.面包屑 start ---------------------------------------->
  103. const parent_name = ref("");
  104. const parent_id = ref("");
  105. const parent_pinyin = ref("");
  106. let getParentNav = async () => {
  107. const listData = await requestDataPromise('/web/getOneWebsiteCategory', {
  108. method: 'GET',
  109. query: {
  110. 'catid': routeId
  111. },
  112. });
  113. if (listData.code == 200) {
  114. parent_name.value = listData.data.alias;
  115. parent_id.value = listData.data.parent_id;
  116. parent_pinyin.value = listData.data.aLIas_pinyin;
  117. } else {
  118. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  119. console.log("错误位置:获取面包屑导航")
  120. console.log("后端错误反馈:", listData.message)
  121. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  122. }
  123. }
  124. //获得父级栏目详情
  125. getParentNav();
  126. //3.面包屑 end ---------------------------------------->
  127. //4.新闻详情 start ---------------------------------------->
  128. //4.1 资讯详情
  129. const newsDetail = ref({})
  130. const routeNewsTtitle = ref("");
  131. //4.2 发布日期
  132. const time = ref("");
  133. //4.3 路径
  134. const routLevelTitle = ref("");
  135. const routLevelId = ref("");
  136. //4.4 是否展示投票
  137. const articleChoice = ref(false);
  138. //4.5 获取详情
  139. async function getPageData() {
  140. const mkdata = await requestDataPromise('/web/selectWebsiteArticleInfo', {
  141. method: 'GET',
  142. query: {
  143. 'articleid': articleId
  144. },
  145. });
  146. if (mkdata.code == 200) {
  147. //判断是否显示投票
  148. if (mkdata.data.is_survey == 1) {
  149. console.log("本篇文章含有投票!")
  150. articleChoice.value = true;
  151. }
  152. //获取内容
  153. newsDetail.value = mkdata.data;
  154. //获取路径
  155. routLevelTitle.value = newsDetail.value.cat_name;
  156. routLevelId.value = newsDetail.value.category_id;
  157. //获取发布时间
  158. time.value = newsDetail.value.updated_at.split(' ')[0];
  159. //修正标题长度
  160. if (newsDetail.value.title.length >= 20) {
  161. routeNewsTtitle.value = newsDetail.value.title.substr(0, 20) + "...";
  162. } else {
  163. routeNewsTtitle.value = newsDetail.value.title
  164. }
  165. } else {
  166. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  167. console.log("错误位置:获取详情内容")
  168. console.log("后端错误反馈:", mkdata.message)
  169. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  170. }
  171. }
  172. getPageData();
  173. //4.新闻详情 end ---------------------------------------->
  174. //5.广告 start ---------------------------------------->
  175. let adImg1 = ref([]);
  176. <<<<<<< HEAD
  177. onMounted(async () => {
  178. =======
  179. let adImg2 = ref([]);
  180. onMounted(async () => {
  181. >>>>>>> 6f7f78215e97bb9cd6b05dcdc651d07789b7b45f
  182. const { $webUrl, $CwebUrl } = useNuxtApp();
  183. //广告1
  184. let url = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=snscw_detail_0001`
  185. const responseAd1 = await fetch(url, {
  186. headers: {
  187. 'Content-Type': 'application/json',
  188. 'Userurl': $CwebUrl,
  189. 'Origin': $CwebUrl
  190. }
  191. });
  192. const resultAd1 = await responseAd1.json();
  193. adImg1.value = resultAd1.data[0];
  194. //广告2
  195. let url2 = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=snscw_detail_0002`
  196. const responseAd2 = await fetch(url2, {
  197. headers: {
  198. 'Content-Type': 'application/json',
  199. 'Userurl': $CwebUrl,
  200. 'Origin': $CwebUrl
  201. }
  202. });
  203. const resultAd2 = await responseAd2.json();
  204. adImg2.value = resultAd2.data[0];
  205. })
  206. //5.广告 end ---------------------------------------->
  207. //6.设置seo信息 start---------------------------------------->
  208. const setData = await requestDataPromise('/web/selectWebsiteArticleInfo', {
  209. method: 'GET',
  210. query: {
  211. 'articleid': articleId
  212. },
  213. });
  214. if (setData.code == 200) {
  215. let seoTitle = setData.data.title;
  216. let seoDescription = setData.data.introduce;
  217. let seoKeywords = setData.data.keyword;
  218. let seoSuffix = setData.data.suffix;
  219. let seoName = setData.data.website_name;
  220. useSeoMeta({
  221. title: seoTitle + "_" + seoName + "_" + seoSuffix,
  222. meta: [
  223. { name: 'description', content: seoDescription + "_" + seoName + "_" + seoSuffix, tagPriority: 10 },
  224. { name: 'keywords', content: seoKeywords + "_" + seoName + "_" + seoSuffix, tagPriority: 10 }
  225. ]
  226. });
  227. } else {
  228. console.log("获取广告数据失败!", setData.message)
  229. }
  230. //6.设置seo信息 end---------------------------------------->
  231. //8.页面图片放大 start---------------------------------------->
  232. const previewVisible = ref(false)
  233. const selectedImage = ref(' ')
  234. const openPreview = (event) => {
  235. if (event.target.tagName === 'IMG') {
  236. selectedImage.value = event.target.src;
  237. previewVisible.value = true;
  238. }
  239. }
  240. const closePreview = () => {
  241. previewVisible.value = false;
  242. }
  243. //8.页面图片放大 end---------------------------------------->
  244. </script>
  245. <style lang="less" scoped>
  246. @import url('@/assets/css/detail.less');
  247. </style>